from django.db import models
from utils.basemodel import BaseModel
# Create your models here.


class CategoryModel(BaseModel):
    cname=models.CharField(max_length=50,verbose_name='分类名称')
    parent=models.ForeignKey('self',null=True,blank=True,on_delete=models.CASCADE,verbose_name='父级分类',related_name='child')
    ishot=models.BooleanField(default=False,verbose_name='是否热门')
    ishome=models.BooleanField(default=False,verbose_name='是否展示在首页')
    isgood = models.BooleanField(default=False, verbose_name='是否推荐')
    class Meta:
        db_table='crousecate'
    def __str__(self):
        return self.cname

class TeacherModel(BaseModel):
    tname=models.CharField(max_length=50,verbose_name='职位')
    intro=models.TextField(verbose_name='简介')
    job=models.CharField(max_length=10,verbose_name='职位')
    headimg=models.ImageField(upload_to='uploads',verbose_name='头像')
    class Meta:
        db_table='fgteacher'
    def __str__(self):
        return self.tname

class CourseModel(BaseModel):
    cname=models.CharField(max_length=50,verbose_name='课程名称')
    catetegory=models.ForeignKey(CategoryModel,on_delete=models.CASCADE,verbose_name='课程分类')
    teacher=models.ForeignKey(TeacherModel,on_delete=models.CASCADE,verbose_name='授课教师')
    cover=models.ImageField(upload_to='uploads',verbose_name='封面')
    level=models.IntegerField(choices=(('1','初级'),('2','中级'),('3','高级')),verbose_name='难度',default=1)
    vedio=models.CharField(max_length=200,verbose_name='视频')
    price=models.DecimalField(max_digits=5,decimal_places=2,verbose_name='价格')
    discount=models.DecimalField(max_digits=5,decimal_places=2,verbose_name='折扣价格')
    ishome=models.BooleanField(default=False,verbose_name='是否推荐')
    ishot=models.BooleanField(default=False,verbose_name='是否热门')
    read=models.IntegerField(default=0,verbose_name='阅读量')
    intro=models.CharField(max_length=20,verbose_name='简介',default='无')
    class Meta:
        db_table='fgcourse'
    def __str__(self):
        return self.cname